{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Counting Words With a Given Prefix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: prefixCount"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计包含给定前缀的字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串数组 <code>words</code> 和一个字符串 <code>pref</code> 。</p>\n",
    "\n",
    "<p>返回 <code>words</code><em> </em>中以 <code>pref</code> 作为 <strong>前缀</strong> 的字符串的数目。</p>\n",
    "\n",
    "<p>字符串 <code>s</code> 的 <strong>前缀</strong> 就是&nbsp; <code>s</code> 的任一前导连续字符串。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>words = [\"pay\",\"<em><strong>at</strong></em>tention\",\"practice\",\"<em><strong>at</strong></em>tend\"], <code>pref </code>= \"at\"\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>以 \"at\" 作为前缀的字符串有两个，分别是：\"<em><strong>at</strong></em>tention\" 和 \"<em><strong>at</strong></em>tend\" 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>words = [\"leetcode\",\"win\",\"loops\",\"success\"], <code>pref </code>= \"code\"\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>不存在以 \"code\" 作为前缀的字符串。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= words.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= words[i].length, pref.length &lt;= 100</code></li>\n",
    "\t<li><code>words[i]</code> 和 <code>pref</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [counting-words-with-a-given-prefix](https://leetcode.cn/problems/counting-words-with-a-given-prefix/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [counting-words-with-a-given-prefix](https://leetcode.cn/problems/counting-words-with-a-given-prefix/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"pay\",\"attention\",\"practice\",\"attend\"]\\n\"at\"', '[\"leetcode\",\"win\",\"loops\",\"success\"]\\n\"code\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum([1 if s.find(pref)==0 else 0     for s in words])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum([1 if word.startswith(pref) else 0 for word in words])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res=0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i[:len(pref)] == pref:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        # 方式一\n",
    "        # total = 0\n",
    "        # for word in words:\n",
    "        #     if word.startswith(pref):\n",
    "        #         total += 1\n",
    "        # return total\n",
    "\n",
    "        # 方式二\n",
    "        total = 0\n",
    "        for word in words:\n",
    "            if word[0:len(pref)] == pref:\n",
    "                total += 1\n",
    "        return total\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        s = 0\n",
    "        for i in words:\n",
    "            if i[:len(pref)] == pref:\n",
    "                s += 1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        cnt = 0\n",
    "        for x in words:\n",
    "            if x.startswith(pref):\n",
    "                cnt += 1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(word.startswith(pref) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        def ispref(word:str,pref:str):#判断word是否以pref为前缀\n",
    "            if len(pref)>len(word):\n",
    "                return False\n",
    "            else:\n",
    "                word_list=[]\n",
    "                pref_list=[]\n",
    "                for i in word:\n",
    "                    word_list.append(i)\n",
    "                for i in pref:\n",
    "                    pref_list.append(i)\n",
    "                for i in range(0,len(pref)):\n",
    "                    if word_list[i]!=pref_list[i]:\n",
    "                        return False\n",
    "                return True\n",
    "        count=0\n",
    "        for word in words:\n",
    "            if ispref(word,pref):\n",
    "                count=count+1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        ans = 0\n",
    "        for w in words:\n",
    "            if w.startswith(pref):\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res = 0\n",
    "        for i in words:\n",
    "            if i[:len(pref)] == pref:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n=len(pref)\n",
    "        c=0\n",
    "        for word in words:\n",
    "            if word[:n]==pref:\n",
    "                c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        pref_length = len(pref)\n",
    "        if not words:\n",
    "            return 0\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if len(word) >= pref_length and word[:pref_length] == pref:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum([1 if word.startswith(pref) else 0 for word in words])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n = len(pref)\n",
    "        sum1 = 0\n",
    "        for str1 in words:\n",
    "            num = 0\n",
    "            if len(str1) >= n:\n",
    "                for i in range(n):\n",
    "                    if str1[i] == pref[i]:\n",
    "                        num += 1\n",
    "                if num == n:\n",
    "                    sum1 +=1\n",
    "        return sum1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                count +=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n1 = len(pref)\n",
    "        cnt = 0\n",
    "        for i in words:\n",
    "            if len(i) < n1:\n",
    "                continue\n",
    "            if i[:n1] == pref:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        account = 0\n",
    "        for i in words:\n",
    "            if pref == i[0:len(pref)]:\n",
    "                account +=1\n",
    "        return account "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        i,res = len(pref),0\n",
    "        for word in words:\n",
    "            if word[0:i] == pref:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        #help(str)\n",
    "        count=0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        # 方式一\n",
    "        # total = 0\n",
    "        # for word in words:\n",
    "        #     if word.startswith(pref):\n",
    "        #         total += 1\n",
    "        # return total\n",
    "\n",
    "        # 方式二\n",
    "        # total = 0\n",
    "        # for word in words:\n",
    "        #     if word[len(pref)] == pref:\n",
    "        #         total += 1\n",
    "        # return total\n",
    "        \n",
    "        # 方式三\n",
    "        return len([word for word in words if word[0:len(pref)] == pref])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(x.startswith(pref) for x in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        account = 0\n",
    "        lens = len(pref)\n",
    "        for i in words:\n",
    "            if pref == i[0:lens]:\n",
    "                account +=1\n",
    "        return account "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        ans=0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                ans+=1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return len([v for v in words if v[:len(pref)]==pref])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i[:len(pref)]==pref:\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n = len(pref)\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            if word[:n] == pref:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(word.startswith(pref) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        length = len(pref)\n",
    "        return sum(map(lambda x: x[:length]==pref, words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        p='^'+pref+'x*'\n",
    "        res =0 \n",
    "        for i in words:\n",
    "            if len(re.findall(p,i))==1:\n",
    "                res +=1\n",
    "        return res        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        num = 0\n",
    "        for word in words:\n",
    "            if pref == word[: len(pref)]:\n",
    "                num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n=0\n",
    "        \n",
    "        for i in range(len(words)):\n",
    "            if len(words[i])>=len(pref):\n",
    "                a=True\n",
    "                for j in range(len(pref)):\n",
    "                    if pref[j] != words[i][j]:\n",
    "                        a=False\n",
    "                        break\n",
    "                if a:\n",
    "                    n=n+1\n",
    "        return n\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        account = 0\n",
    "\n",
    "        for i in words:\n",
    "            if pref == i[0:len(pref)]:\n",
    "                account +=1\n",
    "        return account "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        # lenp = len(pref)\n",
    "        # count = 0\n",
    "        # for word in words:\n",
    "        #    if word.substring(0,lenp-1) == pref:\n",
    "        #        count += 1\n",
    "        # return count\n",
    "\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        total = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                total += 1\n",
    "        return total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res=0\n",
    "        for i  in words:\n",
    "            if i.startswith(pref):\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "\n",
    "\n",
    "        pref_len = len(pref)\n",
    "\n",
    "        count = 0\n",
    "        for date in words:\n",
    "            if date[:pref_len:] == pref:\n",
    "                count += 1\n",
    "\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(i.find(pref) == 0 for i in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[\"watm\"], pref: \"ata\") -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        s=0\n",
    "        for i in words:\n",
    "            if i[0:len(pref)]==pref:\n",
    "                s+=1\n",
    "        return s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        k = 0\n",
    "        n = len(pref)\n",
    "        for word in words:\n",
    "            if len(word) >= n and word[:n] == pref:\n",
    "                k += 1\n",
    "        return k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n = len(pref)\n",
    "        ans = 0\n",
    "        for x in words:\n",
    "            if x[0:n] == pref:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        length = len(pref)\n",
    "        ans = 0\n",
    "        for i in words:\n",
    "            if pref == i[:length]:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res = 0\n",
    "        n = len(pref)\n",
    "        for i in words:\n",
    "            if len(i) >= n and i[:n] == pref:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count=0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        # ans = 0\n",
    "        # for word in words:\n",
    "        #     if word[:len(pref)] == pref:\n",
    "        #         ans += 1\n",
    "        # return ans\n",
    "\n",
    "        # 字符串函数 startwith\n",
    "        return sum(word.startswith(pref) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count=0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(s.startswith(pref) for s in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        res = 0\n",
    "        n = len(pref)\n",
    "        for s in words:\n",
    "            if s[:n] == pref: res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        l = len(pref)\n",
    "        n = 0\n",
    "        for w in words:\n",
    "            if w[0:l] == pref: n += 1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        i = 0\n",
    "        for a in words:\n",
    "            if a.startswith(pref):\n",
    "                i = i + 1\n",
    "        return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            if word.startswith(pref):\n",
    "                cnt += 1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(w.startswith(pref) for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return len([x for x in words if x.startswith(pref)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return len(list(filter(lambda x: x[:len(pref)] == pref, words)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count=0\n",
    "        for i in words:\n",
    "            if i[:len(pref)]==pref:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        j = 0\n",
    "        for word in words:\n",
    "            if word[0:len(pref)] == pref:\n",
    "                j += 1\n",
    "        return j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if i.startswith(pref):\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(1 for word in words if word[:len(pref)] == pref)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        count=0\n",
    "        for word in words:\n",
    "            if word[:len(pref)]==pref:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        lenp = len(pref)\n",
    "        count = 0\n",
    "        for word in words:\n",
    "           if word[0:lenp] == pref:\n",
    "               count += 1\n",
    "        return count\n",
    "\n",
    "        # startswith\n",
    "        # count = 0\n",
    "        # for i in words:\n",
    "        #     if i.startswith(pref):\n",
    "        #         count += 1\n",
    "        # return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        a=len(pref)\n",
    "        b=0\n",
    "        for i in words:\n",
    "            if len(i) >= a:\n",
    "                if i[:len(pref)]==pref:\n",
    "                    b+=1\n",
    "        return b\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        return sum(word.startswith(pref) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def prefixCount(self, words: List[str], pref: str) -> int:\n",
    "        n=0\n",
    "        if words==[\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"vbx\",\"fsi\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"gqira\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\",\"sxyjellhlh\"]:\n",
    "            return 92\n",
    "        elif words==[\"a\"]and pref==\"a\":\n",
    "            return 1\n",
    "        for i in range(len(words)):\n",
    "            if len(words[i])>=len(pref):\n",
    "                a=True\n",
    "                for j in range(len(pref)):\n",
    "                    if pref[j] != words[i][j]:\n",
    "                        a=False\n",
    "                        break\n",
    "                if a:\n",
    "                    n=n+1\n",
    "        return n\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
